<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>test</title>
 <style>
 
 </style>
 <link rel="stylesheet" href="lib/layui-v2.6.3/css/layui.css" media="all">
 <link rel="stylesheet" href="css/public.css" media="all">
 <script src="lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
 <script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
</head>
<body>
    <div class="layuimini-container">
        <div class="layuimini-main"> 
             <fieldset class="table-search-fieldset">
                <legend>搜索信息</legend>
                <div style="margin: 10px 10px 10px 10px" id="btn">
                    <!--<form class="layui-form layui-form-pane" action="">-->
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">角色名称</label>
                                <div class="layui-input-inline">
                                    <!--注意此处input标签里的id-->
                                    <input class="layui-input" name="keyword" id="demoReload" autocomplete="off">
                                </div>
                            </div>
                            
                            <div class="layui-inline">
                                <!--注意此处button标签里的type属性-->
                                <button type="button" class="layui-btn layui-btn-primary"  lay-submit data-type="reload" lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                            </div>
                        </div>
                    <!--</form>-->
                </div>
            </fieldset>   
            <!--注意此处table标签里的id-->
            <table class="layui-table layui-hide" id="test" lay-filter="test"></table>
        </div>
    </div>
    
    <script>
        layui.use(['jquery', 'form', 'table', 'layer', 'tree'], function () {
        var	$ = layui.jquery,
            form = layui.form,
            table = layui.table,
            layer = layui.layer,
            tree = layui.tree;
          
      var tableIns = table.render({
        	elem: '#test',		//对应table标签里的id
            url:'api/test.json',	//从后台获取数据的url
            id:'test',			//此处也需要设置这个属性，后边会用到
            toolbar: '#toolbarDemo',
            method:'post',
            dataType:'json',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols:[[
            	//{ type:"numbers", width:15, align:"center"},
    			//{ type:"checkbox", width:35, align: "center" },
    			{ field:'name',title:'角色名称',width:'20%', align: "center"},
    			{ field:'remark',title:'角色备注',width:'45%', align: "center"},
    			{ title:'权限操作',align: "center",
    					templet:function(d){
    						var test = '<a href="#" class="fa fa-check-square-o" οnclick="selectAuthority('+d.id+')">编辑权限</a>';
            				return test;
	    			}},
    		]],
            limit:3,		//默认6条数据一页
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']//自定义分页布局 
                ,limits:[6,10,15]
                ,first: false //不显示首页
                ,last: false //不显示尾页
              },
            skin: 'line'
        });
         //以下是搜索框进行监测      
         var active = {
        	    reload: function(){
        	      var demoReload = $('#demoReload');	//得到搜索框里已输入的数据
                  console.log("demoReload.val:",$('#demoReload').val());
        	      //执行重载
        	      table.reload('test', {
        	        page: {
        	          curr: 1 //重新从第 1 页开始
        	        }
        	        ,where: {
        	          //name:  demoReload.val()		//在表格中进行搜索
                      name:$('#demoReload').val()
        	        }
        	      },'data');
        	    }
        	  };
        	  
        	  $('#btn .layui-btn').on('click', function(){
        	    var type = $(this).data('type');
        	    active[type] ? active[type].call(this) : '';
        	  });
});
        </script>
    </body>
</html>